Jon Marius shouted too much at the recent
Justin Bieber concert, and now needs to go to the doctor because of his sore
throat. The doctor’s instructions are to say “aaah”. Unfortunately, the
doctors sometimes need Jon Marius to say “aaah” for a while, which Jon
Marius has never been good at. Each doctor requires a certain level of “aah”
– some require “aaaaaah”, while others can actually
diagnose his throat with just a “h”. (They often diagnose
wrongly, but that is beyond the scope of this problem.) Since Jon Marius does
not want to go to a doctor and have his time wasted, he wants to compare how
long he manages to hold the “aaah” with the doctor’s requirements.
(After all, who wants to be all like “aaah” when the doctor wants you to
go “aaaaaah”?)
Each day Jon Marius calls up a different
doctor and asks them how long his “aaah”
has to be. Find out if Jon Marius would waste his time
going to the given doctor.
Input. The input consists of two lines. The first line is
the “aaah” Jon Marius is able to say that day.
The second line is the “aah” the doctor wants to hear. Only lowercase ‘a’
and ‘h’ will be used in the input, and each line will contain
between 0 and 999 ‘a’s, inclusive, followed by a
single ‘h’.
Output. Output “go” if Jon Marius can go to that doctor, and
output “no” otherwise.
Sample
input 1 |
Sample
output 1 |
aaah aaaaah |
no |
|
|
Sample
input 2 |
Sample
output 2 |
aaah ah |
go |
string
Read two lines.
If the length of the second line is longer than the length of the first one, then Marius
will not be able to say the word that the doctor demands. Therefore, he should
not go to the doctor and the answer is “no”. Otherwise, he can go to the doctor.
Algorithm realization
Declare char arrays s1 and s2.
#define MAX 1010
char s1[MAX], s2[MAX];
Read the input lines into
character arrays.
gets(s1);
gets(s2);
Compare the lengths of the lines and print the answer.
if (strlen(s1) < strlen(s2))
printf("no\n");
else
printf("go\n");
Algorithm realization – string
#include <iostream>
#include <string>
using namespace
std;
string s1, s2;
int main(void)
{
cin >> s1 >> s2;
if (s1.size()
< s2.size())
cout << "no"
<< endl;
else
cout << "go"
<< endl;
return 0;
}
Java realization
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
String s1 = con.nextLine();
String s2 = con.nextLine();
if (s1.length()
< s2.length())
System.out.println("no");
else
System.out.println("go");
con.close();
}
}